##########################################
## Copyright 2012-2013 Ceruti Francesco & contributors
##
## This file is part of LiSP (Linux Show Player).
##########################################

import types


class Event:
    '''
    Event perform the connected actions in the thread that emit it.
    '''

    def __init__(self):
        self.actions = []

    def disconnect(self, action):
        if(isinstance(action, types.FunctionType) or isinstance(action, types.MethodType)):
            if(action in self.actions):
                self.actions.remove(action)

    def connect(self, action):
        if(isinstance(action, types.FunctionType) or isinstance(action, types.MethodType)):
            self.actions.append(action)

    def emit(self, *argv, **kargv):
        for act in self.actions:
            act(*argv, **kargv)
